Creating a Development Dump from Production
This guide explains how to create a development database dump from production data. The process is automated through a single command that handles the entire workflow.
Overview
The entire process is handled by a single command that:
- Creates dumps from production
- Imports the dumps locally
- Prepares the data for development
- Creates a final development-ready dump
Prerequisites
-
Zoo running locally
-
Production database read-only credentials in
.../farfalla/mysqldump-farfalla_readonly.cnf:[mysqldump]
host=production-host
user=readonly-user
password=readonly-password
port=3306 -
.../farfalla/database/schema/20241111_farfalla_dev_local_gateways.gzfile for local gateways data
Running the Process
Simply run:
php artisan pla:refresh-local-db-from-prod
This command performs the following steps automatically:
- Creates a dated directory in
storage/app/db/YYYYMMDD/ - Dumps and imports:
- Database schema
- SingleStore projections
- Minimal data from essential tables
- Automatically triggers
pla:prepare-local-db-for-devwhich:- Imports local gateways data
- Updates tenant settings
- Configures development features
- Sets up test data
- Creates a final development-ready dump
Output Files
The command creates these files in the dated directory:
YYYYMMDD___farfalla___prod_dump___schema.sql.gz- Database schemaYYYYMMDD___farfalla___prod_dump___schema_projections.sql.gz- SingleStore projectionsYYYYMMDD___farfalla___prod_dump___minimal_data.sql.gz- Minimal data from essential tablesYYYYMMDD___farfalla___minimal___ready_for_dev.sql.gz- Final development-ready dumpran_at_{timestamp}- Empty file to track when the dump was created
Final Output
After the command completes successfully, you'll have a development-ready database dump at:
.../farfalla/storage/app/db/YYYYMMDD/YYYYMMDD___farfalla___minimal___ready_for_dev.sql.gz
This dump can be shared with the team and used to set up local development environments.
Backup and History
- All previous dumps in a date directory are automatically backed up to
.../farfalla/storage/app/db/YYYYMMDD/backup/{timestamp}/before new dumps are created - Each dump is tracked with a timestamp file
- You can specify different dates to maintain multiple versions
What the Preparation Step Does
When pla:refresh-local-db-from-prod triggers pla:prepare-local-db-for-dev, it performs these adjustments:
-
Database Safety
- Checks if database was already prepared to avoid corruption
- Only runs in local environment
- Clears Redis databases
-
Domain Configuration
- Sets main tenant domain to
farfalla.localhost - Updates all other tenants to use
{slug}.farfalla.localhost - Prefixes all tenant names with "lcl -"
- Clears landing page redirects
- Sets main tenant domain to
-
User Management
- Creates super admin users for all tenants
- Sets default password to 'secret'
- Uses
local@publica.laas the admin email
-
Data Cleanup
- Removes orphaned sign-up intents
- Cleans tracking and analytics data
- Removes custom styles and policies
- Optionally removes user plans without matching orders
-
Security
- Marks the database as prepared to prevent multiple runs
- Disables activity logging during the process
This preparation ensures the database is ready for local development while maintaining data integrity and security.
Troubleshooting
-
If you get connection errors, verify:
- The
mysqldump-farfalla_readonly.cnffile exists and has correct credentials - You can connect to the production database from your machine
- Your local SingleStore instance is running
- The
-
If the dump is missing data:
- Check if all required tables exist in production
- Verify you have proper permissions on the production database
- Check the logs for any skipped tables or errors
-
If preparation fails:
- Ensure you have the latest gateway data file
- Check if all required tables were properly dumped
- Verify your local database permissions